package com.bw.dao.impl;

import com.bw.dao.SupplierDao;
import com.bw.pojo.Supplier;
import com.bw.pojo.vo.SupplierVo;

import java.util.List;

public class SupplierDaoImpl extends BaseDao implements SupplierDao {
    @Override
    public List<SupplierVo> getSupplierList(SupplierVo supplierVo) {
        String sql = "SELECT * FROM `t_supplier` where deleted = 0  ";
        if (null != supplierVo.getSupplierName() && !supplierVo.getSupplierName().isEmpty()) {
            sql += " and INSTR(supplier_name,'" + supplierVo.getSupplierName() + "')";
        }
        sql += " limit ?,?";
        int index = (supplierVo.getPageNum() - 1) * supplierVo.getPageSize();
        List<SupplierVo> list = baseQueryList(SupplierVo.class, sql, index, supplierVo.getPageSize());
        return list;
    }

    @Override
    public void supplierDelAll(String[] supplierId) {

    }

    @Override
    public void supplierAddAll(List<Supplier> list) {

    }


    @Override
    public Integer count(SupplierVo supplierVo) {
        String sql = "SELECT count(1) FROM `t_supplier` where true  ";
        if (null != supplierVo.getSupplierName() && !supplierVo.getSupplierName().isEmpty()) {
            sql += " and INSTR(supplier_name,'" + supplierVo.getSupplierName() + "')";
        }
        Long aLong = baseQueryCount(Long.class, sql);
        return aLong.intValue();
    }

    @Override
    public List<Supplier> getSupplier() {
        String sql = "select * from t_supplier ";
        List<Supplier> list = baseQueryList(Supplier.class, sql);
        return list;
    }

    @Override
    public void getSupplierDel(String uid) {
        String sql = "update t_supplier set deleted = 1 where supplier_id in("+uid+")";
        baseUpdate(sql);
    }
}
